/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.oszero.deliver.server.pretreatment.link.paramcheck.jpush;

import cn.hutool.core.util.StrUtil;
import com.oszero.deliver.server.enums.SmsProviderTypeEnum;
import com.oszero.deliver.server.exception.MessageException;
import com.oszero.deliver.server.model.dto.common.SendTaskDto;
import com.oszero.deliver.server.pretreatment.common.LinkContext;
import com.oszero.deliver.server.pretreatment.common.MessageLink;
import com.oszero.deliver.server.pretreatment.link.paramcheck.ParamStrategy;
import com.oszero.deliver.server.util.MessageLinkTraceUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;

@Service
@RequiredArgsConstructor
public class JPushParamCheck implements MessageLink<SendTaskDto>
{
    @Override
    public void process(LinkContext<SendTaskDto> context) {
        SendTaskDto sendTaskDto = context.getProcessModel();

        Map<String, Object> paramMap = sendTaskDto.getParamMap();

        String alias = paramMap.getOrDefault("alias", "").toString();
        if (StrUtil.isBlank(alias))
        {
            throw new MessageException(sendTaskDto, "目标别名alias参数为空");
        }

        String title = paramMap.getOrDefault("title", "").toString();
        if (StrUtil.isBlank(title))
        {
            throw new MessageException(sendTaskDto, "标题title参数为空");
        }

        String content = paramMap.getOrDefault("content", "").toString();
        if (StrUtil.isBlank(content))
        {
            throw new MessageException(sendTaskDto, "消息内容content参数为空");
        }

        MessageLinkTraceUtils.recordMessageLifecycleInfoLog(sendTaskDto, "完成极光消息参数校验");
    }


}
